package com.dorsica.dbupdate;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;

/**
 * 
 * @author jessica
 */
@Mojo(name = "install")
public class InstallMojo extends DbUpdateAbstractMojo {

    public void execute() throws MojoExecutionException {

        try {
            createHistoryTable();
        } catch (SQLException e) {
            throw new MojoExecutionException("can't create history table", e);
        }
    }

    public void createHistoryTable() throws SQLException {

        if (!doesTableExists(tableName)) {
            try (Connection c = dbConnect()) {

                Statement st = c.createStatement();

                st.execute("create table " + tableName
                        + "(FILE_PATH VARCHAR(50) NOT NULL)");

            }
        }
    }

}
